<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function createUserWithBalance(): \Illuminate\Http\JsonResponse
    {
        // 创建新用户并设置余额
        $user = User::create([
            'name' => 'John Doe',
            'email' => 'john.doe@example.com',
            'password' => bcrypt('password123'), // 请确保在实际应用中安全地处理密码
            'balance' => 100.00,
        ]);

        // 检查用户是否成功创建
        if ($user) {
            return response()->json(['message' => 'User created successfully with balance.', 'user' => $user], 201);
        } else {
            return response()->json(['message' => 'Failed to create user.'], 500);
        }
    }
}
